package com.knowswift.common.utils.getui;

import com.getui.push.v2.sdk.dto.req.Audience;
import com.getui.push.v2.sdk.dto.req.Settings;
import com.getui.push.v2.sdk.dto.req.message.PushChannel;
import com.getui.push.v2.sdk.dto.req.message.PushDTO;
import com.getui.push.v2.sdk.dto.req.message.PushMessage;
import com.getui.push.v2.sdk.dto.req.message.RevokeBean;
import com.getui.push.v2.sdk.dto.req.message.android.GTNotification;
import lombok.Data;
import lombok.Getter;

/**
 * <p>
 * 基于个推SDK设计的Push参数的建设者模式类
 * 实现链式装配
 **/

@Data
@Getter
public class PushBuilder<T> {

    private PushDTO<T> pushDTO;

    private String requestId;
    private String taskName;
    private String groupName;
    private Settings settings;
    private T audience;
    private PushMessage pushMessage;
    private PushChannel pushChannel;

    private MessageBuilder messageBuilder;

    public PushBuilder<T> setRequestId(String requestId) {
        pushDTO.setRequestId(requestId);
        return this;
    }

    public PushBuilder<T> setTaskName(String taskName) {
        pushDTO.setTaskName(taskName);
        return this;
    }

    public PushBuilder<T> setGroupName(String groupName) {
        pushDTO.setGroupName(groupName);
        return this;
    }

    public PushBuilder<T> setSettings(Settings settings) {
        pushDTO.setSettings(settings);
        return this;
    }

    public PushBuilder<T> setAudience(T audience) {
        pushDTO.setAudience(audience);
        return this;
    }

    public PushBuilder<T> setPushMessage(PushMessage pushMessage) {
        pushDTO.setPushMessage(pushMessage);
        return this;
    }

    public PushBuilder<T> setPushChannel(PushChannel pushChannel) {
        pushDTO.setPushChannel(pushChannel);
        return this;
    }

    public static <T> PushBuilder<T> create() {
        return new PushBuilder<>();
    }

    public PushDTO<T> build() {
        return pushDTO;
    }

    public PushBuilder<T> apply() {
        pushDTO = new PushDTO<>();
        return this;
    }

    private PushBuilder<T> getBuilder() {
        return this;
    }

    private Chain getChain() {
        return new Chain();
    }

    class Chain {
        public PushBuilder<T> and() {
            return getBuilder();
        }
    }

    public MessageBuilder applyPushMessage() {
        this.pushMessage = new PushMessage();
        this.pushDTO.setPushMessage(pushMessage);
        return new MessageBuilder();
    }

    class MessageBuilder {
        public MessageBuilder withNetworkType(Integer networkType) {
            pushMessage.setNetworkType(networkType);
            return this;
        }

        public MessageBuilder withDuration(String duration) {
            pushMessage.setDuration(duration);
            return this;
        }

        public Chain withNotification(GTNotification notification) {
            pushMessage.setNotification(notification);
            return getChain();
        }

        public Chain withTransmission(String transmission) {
            pushMessage.setTransmission(transmission);
            return getChain();
        }

        public Chain withRevoke(RevokeBean revoke) {
            pushMessage.setRevoke(revoke);
            return getChain();
        }
    }


    public static void main(String[] args) {
        GTNotification gtNotification = new GTNotification();
        PushDTO<Audience> dto = PushBuilder.<Audience>create()
                .apply().setRequestId("")
                .setAudience(new Audience())
                .applyPushMessage()
                .withTransmission("www")
                .and()
                .build();
        dto.setPushChannel(null);
    }
}
